package com.tiger.userClient.http.news;

import com.tiger.userClient.http.news.dto.ListDto;
import com.tiger.userClient.http.news.dto.PageDto;
import com.tiger.utils.ResponseUtil;
import org.apache.axis.AxisFault;
import org.springframework.web.bind.annotation.*;

import javax.xml.rpc.ServiceException;

@RestController
@RequestMapping("/news")
public class NewsController {

    private final NewsService newsService;

    public NewsController(NewsService newsService) {
        this.newsService = newsService;
    }

    @PostMapping("list")
    public Object list(@RequestBody ListDto data) throws AxisFault, ServiceException {
        String result = newsService.queryNews(data.getStart(), data.getEnd());
        return ResponseUtil.successRes(result);
    }

    @GetMapping("detail/{id}")
    public Object detail(@PathVariable("id") int id) throws AxisFault, ServiceException {
        String result = newsService.detail(id);
        return ResponseUtil.successRes(result);
    }

    @PostMapping("page")
    public Object test(@RequestBody() PageDto dto) throws AxisFault, ServiceException {
        String result = newsService.queryNewsByContentId(dto.getContentid(), dto.getStart(), dto.getCount());
        //String result = "[{\"date\":\"2024-06-04 08:40:54\",\"treeid\":\"1092\",\"author\":\"张胜男\",\"id\":\"50176\",\"title\":\"我校第十二届校友周系列活动成功举行\",\"url\":\"http://news.swun.edu.cn/info/1004/131465.htm\"},{\"date\":\"2024-06-03 17:32:48\",\"treeid\":\"1092\",\"author\":\"冶鹏 郝芳芳\",\"id\":\"50158\",\"title\":\"我校心理情景剧在第七届全国高校心理情景剧优秀剧目展中获全国二等奖\",\"url\":\"http://news.swun.edu.cn/info/1004/131444.htm\"},{\"date\":\"2024-06-03 13:34:00\",\"treeid\":\"1092\",\"author\":\"江宬侥\",\"id\":\"50160\",\"title\":\"学校召开智库建设工作调研座谈会\",\"url\":\"http://news.swun.edu.cn/info/1004/131450.htm\"},{\"date\":\"2024-05-31 15:25:58\",\"treeid\":\"1092\",\"author\":\"冉拉更惹\",\"id\":\"50147\",\"title\":\"我校代表队在四川省第四届“贡嘎杯”青少年校园体育联赛中获4个一等奖\",\"url\":\"http://news.swun.edu.cn/info/1004/131387.htm\"},{\"date\":\"2024-05-31 15:24:57\",\"treeid\":\"1092\",\"author\":\"张洁\",\"id\":\"50146\",\"title\":\"学校召开2024年征兵工作专题会议\",\"url\":\"http://news.swun.edu.cn/info/1004/131388.htm\"},{\"date\":\"2024-05-31 09:11:39\",\"treeid\":\"1092\",\"author\":\"平海涛\",\"id\":\"50157\",\"title\":\"我校药学院与中央民族大学药学院举行合作协议签订暨研究生优质生源基地授牌仪式\",\"url\":\"http://news.swun.edu.cn/info/1004/131433.htm\"},{\"date\":\"2024-05-30 19:07:10\",\"treeid\":\"1092\",\"author\":\"何雄浪\",\"id\":\"50148\",\"title\":\"我校经济学院与成都师范学院开展“铸牢中华民族共同体意识，加强三全育人”工作座谈交流\",\"url\":\"http://news.swun.edu.cn/info/1004/131390.htm\"},{\"date\":\"2024-05-30 17:33:23\",\"treeid\":\"1092\",\"author\":\"石川\",\"id\":\"50159\",\"title\":\"我校成功举办2024年“团结杯”大学生创新大赛启动仪式\",\"url\":\"http://news.swun.edu.cn/info/1004/131389.htm\"},{\"date\":\"2024-05-29 19:09:34\",\"treeid\":\"1092\",\"author\":\"陈希\",\"id\":\"50149\",\"title\":\"【中华民族共同体大讲堂】跟着总书记学历史——我校“三星堆科普教育系列活动”顺利举办\",\"url\":\"http://news.swun.edu.cn/info/1004/131372.htm\"},{\"date\":\"2024-05-28 08:40:52\",\"treeid\":\"1092\",\"author\":\"刘冬忆\",\"id\":\"50129\",\"title\":\"学校召开第十二次党代会筹备工作动员部署会\",\"url\":\"http://news.swun.edu.cn/info/1004/131342.htm\"},{\"date\":\"2024-05-27 15:03:34\",\"treeid\":\"1092\",\"author\":\"何宗\",\"id\":\"50099\",\"title\":\"学校举办“体验信任希望 展示青春力量”第十二届校园原创心理情景剧大赛\",\"url\":\"http://news.swun.edu.cn/info/1004/131290.htm\"},{\"date\":\"2024-05-27 08:41:59\",\"treeid\":\"1092\",\"author\":\"朱成林\",\"id\":\"50131\",\"title\":\"我校教师在第七届四川省科普讲解大赛中获得佳绩\",\"url\":\"http://news.swun.edu.cn/info/1004/131314.htm\"},{\"date\":\"2024-05-27 08:41:17\",\"treeid\":\"1092\",\"author\":\"地娜尔·阿旦别克\",\"id\":\"50130\",\"title\":\"我校师生在第十四届全国旅游院校服务技能（导游服务）大赛中获得佳绩\",\"url\":\"http://news.swun.edu.cn/info/1004/131343.htm\"},{\"date\":\"2024-05-24 20:48:52\",\"treeid\":\"1092\",\"author\":\"秦一学\",\"id\":\"50085\",\"title\":\"学校召开校纪委全委会\",\"url\":\"http://news.swun.edu.cn/info/1004/131276.htm\"},{\"date\":\"2024-05-23 20:50:23\",\"treeid\":\"1092\",\"author\":\"谭晓宇  雷鹏飞 杜娟\",\"id\":\"50086\",\"title\":\"我校举行学雷锋志愿者“雷锋班”开班仪式\",\"url\":\"http://news.swun.edu.cn/info/1004/131256.htm\"},{\"date\":\"2024-05-22 21:00:11\",\"treeid\":\"1092\",\"author\":\"杜芳\",\"id\":\"50091\",\"title\":\"我校在第四届四川省高校教师教学创新大赛中获佳绩\",\"url\":\"http://news.swun.edu.cn/info/1004/131179.htm\"},{\"date\":\"2024-05-22 20:52:25\",\"treeid\":\"1092\",\"author\":\"兰子玲\",\"id\":\"50088\",\"title\":\"【一院一品•师德师风建设工作案例】药学院：党建引领争创示范样板 使命担当践行培根铸魂\",\"url\":\"http://news.swun.edu.cn/info/1004/131206.htm\"},{\"date\":\"2024-05-22 14:53:01\",\"treeid\":\"1092\",\"author\":\"陈希\",\"id\":\"50046\",\"title\":\"我校集体和个人在第十二届国家民委青年读书演讲活动中荣获佳绩\",\"url\":\"http://news.swun.edu.cn/info/1004/131176.htm\"},{\"date\":\"2024-05-22 09:52:51\",\"treeid\":\"1092\",\"author\":\"陈顺强\",\"id\":\"50089\",\"title\":\"学校召开本科教育教学审核评估工作协调会\",\"url\":\"http://news.swun.edu.cn/info/1004/131181.htm\"},{\"date\":\"2024-05-21 21:08:48\",\"treeid\":\"1092\",\"author\":\"陈希\",\"id\":\"50090\",\"title\":\"我校举办2024年各族青年铸牢实践乡村行——走进双流永安专场活动\",\"url\":\"http://news.swun.edu.cn/info/1004/131197.htm\"}]";
        return ResponseUtil.successRes(result);
    }
}
